<?php
namespace Admin\Controller;
//use Think\Controller;
class BusinessController extends CommontController {
    //业务范围添加
    public function add(){
        //实现前台菜单添加完成
        $businessModel=D("Business");
        if(IS_POST){
            if($businessModel->create()){
                if($businessModel->add()){
                    $this->success("添加成功",U("Business/index"));die;
                }else{
                    $this->error("添加失败".$businessModel->getError());
                }
            }else{
                $this->error($businessModel->getError());
            }
        }

        //渲染模板
        $this->display();
    }
    //前台菜单列表
    public function index(){
        $businessModel=D("Business");
        //分页操作
        $count=$businessModel->count();
        $page=new \Think\Page($count,3);
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
        $this->pageList=$page->show();
        $list=$businessModel->order('bu_id desc')->limit($page->firstRow.','.$page->listRows)->select();
        $this->assign('list',$list);
        $this->display();
    }
    //前台菜单的修改
    public function upd(){
        $businessModel=D("Business");
        //前台菜单修改完成
        if(IS_POST){
            if($businessModel->create()){
                if($businessModel->save()!==false){
                    $this->success("修改成功",U("Business/index"));die;
                }else{
                    $this->error("修改失败");
                }
            }else{
                $this->error($businessModel->getError());
            }
        }
        //前台菜单回显
        $bu_id=I('get.bu_id');
        $list=$businessModel->find($bu_id);
        $this->assign('list',$list);
        $this->display();  
    }
    // //前台菜单的删除
    public function del(){
        $businessModel=D("Business");
        $bu_id=I('get.bu_id');
        $data=$businessModel->delete($bu_id);
        if($data){
            $this->success("删除成功",U('Business/index'));die;
        }else{
            $this->error("删除失败");
        }
    }
    
}